package com.qt.socket.work2;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.MulticastSocket;

/**
 * @Author zsf
 * @Date 2023/10/5 1:27
 * @Version 1.0
 */
public class ReceiveMessageWork1 {

    public static void main(String[] args) throws IOException {


        /**
         * 单播，组播，广播
         * @param args
         * @throws IOException
         */

        MulticastSocket ms = new MulticastSocket(10000);
        ms.joinGroup(InetAddress.getByName("224.0.1.0"));
        byte[] bytes = new byte[1024];
        DatagramPacket dp = new DatagramPacket(bytes, bytes.length);

        while (true) {
            ms.receive(dp);
            String data = new String(dp.getData(),0,dp.getLength());
            System.out.println("接收到数据："+data);
            if("886".equals(data)){
                break;
            }
        }
        ms.close();


    }

}
